<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category  Zend
 * @package   Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 *
 */

/** @see Zend_DataGrid_Column */
require_once 'Zend/DataGrid/Column.php';



/**
 * Zend_DataGrid_Column_Selectbox
 *
 * The cells in the column will be displayed using the data indexed by {@link setDataField}.
 * You can customize the display by setting {@link setDataFormat}.
 *
 * If {@link getReadOnly} is false, the Column will display cells in edit mode with dropdown lists.
 * Otherwise, a static text is displayed. The currently selected dropndown list item is specified by the data indexed with {@link getDataValueField}.
 *
 * @category   Zend
 * @package    Zend_DataGrid
 * @subpackage Column
 * @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd     New BSD License
 * @version   $Id: DropDownList.php 6137 2008-09-19 11:43:27Z azoungrana $
 */
class Zend_DataGrid_Column_Selectbox extends Zend_DataGrid_Column
{

    /**
     * The data field value
     *
     * @var string
     */
    protected $_dataValueField = null;

    /**
     * The data source
     *
     * @var mixed
     */
    protected $_listDataSource = null;

    /**
     * The data text field
     *
     * @var string
     */
    protected $_listTextFields = array();

    /**
     * The data list text field
     *
     * @var string
     */
    protected $_listTextFormat = null;

    /**
     * The data list value
     *
     * @var string
     */
    protected $_listValueField = null;

    /**
     * Whether the items in the column can be edited. Defaults to false.
     *
     * @var boolean
     */
    protected $_readOnly = false;


    /**
     * Sets the field of the data source that provides the key selecting an item in dropdown list
     *
     * @param  string $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setDataValueField($value)
    {
        $this->_dataValueField = (string) $value;
        return $this;
    }

    /**
     * Gets the field of the data source that provides the key selecting an item in dropdown list
     *
     * @return string
     */
    public function getDataValueField()
    {
        return $this->_dataValueField;
    }

    /**
     * Sets data source to be bound to the dropdown list boxes
     *
     * @param  mixeds $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setListDataSource($value)
    {
        $this->_listDataSource = $value;
        return $this;
    }

    /**
     * Gets data source to be bound to the dropdown list boxes
     *
     * @return mixed
     */
    public function getListDataSource()
    {
        return $this->_listDataSource;
    }

    /**
     * Sets the data field used to populate the texts of the dropdown list items. Defaults to empty.
     *
     * @param  string $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setListTextField($value)
    {
        $this->clearListTextField();
        $this->_listTextField = (string) $value;
        return $this;
    }

    /**
     * Returns the data fields used to populate the texts of the dropdown list items.
     *
     * @return string
     */
    public function getListTextFields()
    {
        return $this->_listTextFields;
    }

    /**
     * Adds a data field used to populate the texts of the dropdown list items
     *
     * @param string $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function addListTextField($value)
    {
        $this->_listTextFields[] = (string) $value;
        return $this;
    }

    /**
     * Adds data fields used to populate the texts of the dropdown list items
     *
     * @param array $values
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function addlistTextFields(array $values)
    {
        foreach ($values as $field)
            $this->addListTextField($field);

        return $this;
    }

    /**
     * Clear the data field used to populate the texts of the dropdown list items. Defaults to empty.
     *
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function clearListTextField()
    {
        $this->_listTextFields = array();
        return $this;
    }

    /**
     * Sets the formatting string used to control how the list item texts will be displayed
     *
     * @param  string $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setListTextFormat($value)
    {
        $this->_listTextFormat = (string) $value;
        return $this;
    }

    /**
     * Gets the formatting string used to control how the list item texts will be displayed
     *
     * @return string
     */
    public function getListTextFormat()
    {
        return $this->_listTextFormat;
    }

    /**
     * Sets the data field used to populate the values of the dropdown list items. Defaults to empty
     *
     * @param  string $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setListValueField($value)
    {
        $this->_listValueField = (string) $value;
        return $this;
    }

    /**
     * Gets the data field used to populate the values of the dropdown list items. Defaults to empty
     *
     * @return string
     */
    public function getListValueField()
    {
        return $this->_listValueField;
    }

    /**
     * Set element read only
     *
     * @param  boolean $value
     * @return Zend_DataGrid_Column_Selectbox
     */
    public function setReadOnly($value)
    {
        $this->_readOnly = (boolean) $value;
        return $this;
    }

    /**
     * Retrieve element read only
     *
     * @return boolean
     */
    public function getReadOnly()
    {
        return $this->_readOnly;
    }



}
